<template>
  <div id="stopdialog">
    <commonformdialog
      :isshowDialogs="isshowDialog"
      :isshowconfirmbtn="false"
      :dialogWidth="'35%'"
      :enterTitle="false"
      :isshowimportTitle="false"
      :dialogTitle="`退学-${dialogparams.name}`"
      @closetextDialog="closetextDialog"
      @confirmbtn='confirmbtn'
      :topHeight='"25vh"'
    >

   <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="80px">
  <el-form-item label="选择原因" prop="cost_reason">
    <el-select v-model="formData.cost_reason" placeholder="选择退学原因" clearable :style="{width: '100%'}">
      <el-option v-for="(item, index) in dropoutOption" :key="index" :label="item.title" :value="item.id"
        :disabled="item.disabled"></el-option>
    </el-select>
  </el-form-item>
  <el-form-item label="退款金额" prop="cost_money">
    <el-input v-model="formData.cost_money" placeholder="请输入退款金额" clearable :style="{width: '100%'}">
        <template slot="append">元</template>
    </el-input>
  </el-form-item>
</el-form>


    </commonformdialog>
  </div>
</template>

<script>
//引入弹窗
import commonformdialog from '@/components/commondialog/commondialog'
//api
import {dropout} from '@/api/student'
import {getSessionStorage} from '@/utils/accessToken'
export default {
  data() {
    return {
      formData: {
        cost_money: '',
        cost_reason: '',
      },
      rules: {
        cost_reason: [{
          required: true,
          message: '请选择退学原因',
          trigger: 'change'
        }],
        cost_money: [{
          required: true,
          message: '请输入退款金额',
          trigger: 'blur'
        }],
      },
      dropoutOption: [],
    }
  },
  components: {
    commonformdialog,
  },
  props: {
    //是否显示弹窗
    isshowDialog: {
      type: Boolean,
      default: false,
    },
    //弹窗参数
    dialogparams:{
      type:Object,
      default:()=>{
        return {}
      }
    }
  },
  methods:{
      //关闭弹窗
    closetextDialog() {
      this.$refs['elForm'].resetFields()
      this.$emit('closetextDialog')
    },
    //点击确认
    confirmbtn(){
        this.$refs['elForm'].validate( async valid => {
        if (!valid) return
        let params = {
            student_id:this.dialogparams.id,
            cost_money:this.formData.cost_money,
            cost_reason:this.formData.cost_reason
        }
        let data = await dropout(params)
        if(data.code=='0000'){
            this.$message.success('退学成功！')
            this.$emit('confirmdropout')
            this.$refs['elForm'].resetFields()
        }
      })

    }
  },
  mounted(){
    this.dropoutOption = getSessionStorage('Options')[26]
  }
}
</script>

<style scoped lang='scss'>

</style>
